﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using PJ.Business;
using Microsoft.Practices.Composite.Events;

namespace PJ.Presentation
{
    public abstract class EntityFragmentViewModel : BusinessObjectViewModel, IEntityFragmentModel
    {
        public EntityFragmentViewModel(IView view, IEventAggregator aggregator, IEntityFragmentService service) : base(view, aggregator, service)
        {
        }

        /// <summary>
        /// GetValues. Sets the businness object properties using the model property values
        /// </summary>
        /// <param name="businessObject">business object to update</param>
        public override IBusinessObject GetValues(IBusinessObject businessObject)
        {
            base.GetValues(businessObject);
            ((IEntityFragment)businessObject).ParentID = ParentID;
            return businessObject;
        }
        /// <summary>
        /// SetValues. Sets the model properties using the businessobject property values
        /// </summary>
        /// <param name="businessObject"></param>
        public override void SetValues(IBusinessObject businessObject)
        {
            base.SetValues(businessObject);
            ParentID = ((IEntityFragment)businessObject).ParentID;
        }
        
        public string ParentID
        {
            get { return (string)ThreadUnsafeGetValue(ParentIDProperty); }
            set { ThreadUnsafeSetValue(ParentIDProperty, value); }
        }

        public static readonly DependencyProperty ParentIDProperty =
            DependencyProperty.Register("ParentID", typeof(string), typeof(EntityViewModel), new UIPropertyMetadata(""));

    }
}
